package com.xinghanlaser.applet.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinghanlaser.applet.base.common.exception.ServiceException;
import com.xinghanlaser.applet.entity.DealerSecretKey;
import com.xinghanlaser.applet.service.IDealerSecretKeyService;
import com.xinghanlaser.applet.mapper.DealerSecretKeyMapper;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
* @author XH-YF-TSDN-0080
* @description 针对表【dealer_secret_key】的数据库操作Service实现
* @createDate 2024-05-07 16:15:41
*/
@Service
public class DealerSecretKeyServiceImpl extends ServiceImpl<DealerSecretKeyMapper, DealerSecretKey>
    implements IDealerSecretKeyService {

    @Override
    public Long getDealerIdByName(String dealerName) {
        return Optional.ofNullable(
            getOne(Wrappers.lambdaQuery(new DealerSecretKey())
                .select(DealerSecretKey::getDealerName, DealerSecretKey::getBindUserId)
                .eq(DealerSecretKey::getDealerName, dealerName)
                .last("LIMIT 1 ")
            )
        )
        .map(DealerSecretKey::getBindUserId)
        .orElseThrow(() -> new ServiceException("经销商不存在或未绑定用户"));
    }
}




